﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Packet.Records;

namespace System.Net.DnsToolkit.Serializer.Stream.Writer {
    public class RecordWriterProvider : IRecordWriterProvider<System.IO.Stream> {

        private readonly IDictionary<QTypeEnum, IRecordWriter<System.IO.Stream>> _recordIndex;

        public RecordWriterProvider(params IRecordWriter<System.IO.Stream>[] recordwriters) {
            _recordIndex = new Dictionary<QTypeEnum, IRecordWriter<System.IO.Stream>>();
            Array.ForEach(recordwriters, r => _recordIndex.Add(r.QTypeEnum, r));
        }

        public IRecordWriter<System.IO.Stream> Provide(QTypeEnum qTypeEnum) {

            if (!_recordIndex.ContainsKey(qTypeEnum)) {
                throw new NotImplementedException(string.Format("QTypeEnum.{0}", qTypeEnum));
            }

            return _recordIndex[qTypeEnum];
        }

    }
}
